package com.api.shopapi.mapper;

import com.api.shopapi.entity.CashierCart;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface CashierCartMapper {
    @Insert("insert into cashier_cart" +
            "(" +
            "CashierCartCode," +
            "UserCode," +
            "Price," +
            "GovernmentCode" +
            ")" +
            " value" +
            "(" +
            "#{cashierCart.CashierCartCode}," +
            "#{cashierCart.UserCode}," +
            "#{cashierCart.Price}," +
            "#{cashierCart.GovernmentCode}" +
            ")")
    public int insert(@Param("cashierCart") CashierCart cashierCart);

    @Update("update cashier_cart set " +
            "UserCode = #{cashierCart.UserCode}," +
            "Price=#{cashierCart.Price}," +
            "GovernmentCode=#{cashierCart.GovernmentCode}" +
            " where CashierCartCode=#{cashierCart.CashierCartCode}")
    public int update(@Param("cashierCart") CashierCart cashierCart);

    @Delete("delete from cashier_cart where CashierCartCode=#{cashierCartCode}")
    public int delete(@Param("cashierCartCode") String cashierCartCode);

    @Select("select * from cashier_cart")
    public List<CashierCart> getList();

    @Select("select * from cashier_cart where CashierCartCode=#{cashierCartCode} limit 1")
    public CashierCart getByCashierCartCode(@Param("cashierCartCode") String cashierCartCode);

    @Select("select * from cashier_cart where userCode=#{userCode} and governmentCode=#{governmentCode} limit 1")
    public CashierCart getByUserCodeGovernmentCode(@Param("userCode") String userCode,
                                            @Param("governmentCode") String governmentCode);


}
